import { request } from "../../request/index.js"
import regeneratorRuntime from '../../lib/runtime/runtime'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods: [],
    isFoucs: false,
    inpValue: ''
  },
  TimeId: -1,
  handleInput(e) {
    const { value } = e.detail

    if (!value.trim()) {
      this.handleCancel()
      clearTimeout(this.TimeId)
      return
    }
    this.setData({
      isFoucs: true
    })

    clearTimeout(this.TimeId)
    this.TimeId = setTimeout(() => {
      this.qsearch(value)
    }, 1000)
  },
  async qsearch(query) {
    const res = await request({ url: '/goods/search', data: { query } })
    console.log(res);
    this.setData({
      goods: res.goods
    })

  },
  handleCancel() {
    this.setData({
      inpValue: '',
      isFoucs: false,
      goods: []
    })
  }
})